﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using KioskViewerBLL.BLLObjects;

public partial class SelectTopic : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
        }
    }

    protected string generateSelectTopicTable()
    {        
        if (ViewState["generateSelectTopicTable"] == null)
        {
            IList<TopicObj> topics = KioskViewerDAL.DataObjects.DataAccess.ITopicDao.GetAll_topic();
            ViewState["generateSelectTopicTable"] = generateDynamicTable(1, topics, "width: 100%;text-align: center;", "text-align: center; width: 50%");
        }
        //Microsoft.SqlServer.Server.        
        return (string)ViewState["generateSelectTopicTable"];
    }

    private string generateDynamicTable(int noCol, IList<TopicObj> topics, string tblStyle, string cellStyle)
    {
        StringBuilder dTable = new StringBuilder(string.Format("<table style='{0}'>",tblStyle));

        // how many rows
        int noRows = ( (topics.Count - 1 ) / noCol) -1 ;
        if (noRows < 0) noRows = 0;

        for (int currentRow = 0; currentRow <= noRows; currentRow++)
        {
            dTable.Append("<tr>");
            for (int currentCol = 0; currentCol <= noCol; currentCol++)
            {
                dTable.Append(string.Format("<td style=''>",cellStyle));
                try
                {
                    //dTable.Append(string.Format("current Row: {0}; current col {1}", currentRow, currentCol))
                    TopicObj currentTopic = (TopicObj)topics[(currentRow * noCol) + currentCol];
                    //String stringFlash = Common.FlashObj.Replace("%%Label%%", "Song").Replace("%%Link%%", "http://localhost:4792/KioskViewer/BKMainCategory.aspx");            
                    String stringFlash = Common.FlashObj.Replace("%%Label%%", currentTopic.Flash_label).Replace("%%Link%%", currentTopic.Goto_url );
                    dTable.Append(stringFlash);
                }
                catch { }
                dTable.Append("</td>");
            }
            dTable.Append("</tr>");
        }
        return dTable.Append("</table>").ToString();
    }
}
